package com.design.fitment.adapter;

/**
 * Created by Administrator on 2016/1/12 0012.
 */


import java.util.List;

import android.content.Context;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.design.fitment.app.MyApplication;
import com.design.fitment.entity.HomeGallery;


public class GridViewAdapter extends BaseAdapter {
    private Context context;
    private  List<HomeGallery.DataEntity> entities;

    public GridViewAdapter(Context context, List<HomeGallery.DataEntity> entities) {
        this.context = context;
        this.entities = entities;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageview; // 声明ImageView的对象
        if (convertView == null) {
            imageview = new ImageView(context); // 实例化ImageView的对象

            imageview.setPadding(2, 0,2, 0); // 设置ImageView的内边距
        } else {
            imageview = (ImageView) convertView;
        }

        MyApplication.getApp().getImageLoader().displayImage(entities.get(position).getImgUrl(), imageview, MyApplication.getApp().getImageOptions());
        return imageview; // 返回ImageView
    }

    /*
     * 功能：获得当前选项的ID
     *
     * @see android.widget.Adapter#getItemId(int)
     */
    @Override
    public long getItemId(int position) {
        //System.out.println("getItemId = " + position);
        return position;
    }

    /*
     * 功能：获得当前选项
     *
     * @see android.widget.Adapter#getItem(int)
     */
    @Override
    public Object getItem(int position) {
        return position;
    }

    /*
     * 获得数量
     *
     * @see android.widget.Adapter#getCount()
     */
    @Override
    public int getCount() {
        return entities.size();
    }



}


